//
//  MainViewController.swift
//  sina weibo
//
//  Created by 万美琳 on 15/12/14.
//  Copyright © 2015年 Eleven. All rights reserved.
//

import UIKit

class MainViewController: UITabBarController {

    let mainTabBar = MainTabBar()
    
  @objc  private func composeBtnDidClick() {
    
    print(__FUNCTION__)
    
    }
    
    override func viewDidLoad() {
        super.viewDidLoad()
        //因为要tabbar要再添加一个按钮，但是tabBar 是只读属性 不能够直接进行设置，所以要自定义tabbar ， 并使用  KVC 在运行时 间接赋值 (改变身份)
        
        let mainTabbar = MainTabBar()
        
        mainTabbar.composeBtn.addTarget(self, action: "composeBtnDidClick", forControlEvents: .TouchUpInside)
        setValue(mainTabBar, forKey: "tabBar")
        
        //添加子视图控制器
        addChildViewControllers()
    }
    
    private func addChildViewControllers() {
        addChildViewController(HomeTableViewController(), title: "首页", imageName: "tabbar_home")
        addChildViewController(MessageTableViewController(), title: "消息", imageName: "tabbar_message_center")
        addChildViewController(DiscoverTableViewController(), title: "发现", imageName: "tabbar_discover")
        addChildViewController(ProfileTableViewController(), title: "我", imageName: "tabbar_profile")
    }
    
    private func addChildViewController(vc: UITableViewController , title:String ,imageName:String) {
        let nav = UINavigationController(rootViewController: vc)
        addChildViewController(nav)
        vc.title = title
        vc.tabBarItem.image = UIImage(named: imageName)
    }
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    

    override func didReceiveMemoryWarning() {
        super.didReceiveMemoryWarning()
        // Dispose of any resources that can be recreated.
    }
    

    
}
